package com.madarasan.notneeded;

import java.util.ArrayList;
import java.util.List;

import com.madarasan.SkiDroid.MyApplication;
import com.madarasan.SkiDroid.R;
import com.madarasan.resorts.ShowResortGeneralInfo;

import android.app.ListActivity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;


public class ResortList extends ListActivity {
	
		
    
	ArrayList<ArrayList<String>> resorts = new ArrayList<ArrayList<String>>();
	
   
	
    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        
        Log.i("ResortList", "loading feed..");
        
        loadFeed();
    }

	public void loadFeed(){
    	try{
	    	
    	
    		
    		Bundle informations = getIntent().getExtras();
    		
    		resorts = (ArrayList<ArrayList<String>>) informations.getSerializable("theList");
    		
    			
    			
    			List<String> providerNames = new ArrayList<String>();
    	    	for (Integer i=0; i<resorts.size();i++){
    	    		
    	    		providerNames.add(resorts.get(i).get(0).toString());
    	    	}
    			
    	    
    			
    	        setContentView(R.layout.cities);
    		
	    	
    	    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.row,providerNames);
	    	this.setListAdapter(adapter);
	    	
	    	
	    	
	    	final ListView lv = getListView();
	    	lv.setItemsCanFocus(false);
	    	lv.setChoiceMode(ListView.CHOICE_MODE_SINGLE);   
    	} catch (Throwable t){
    		Log.e("ProviderList",t.getMessage(),t);
    	}
    }
	
	
	@Override
	protected void onListItemClick(ListView l, View v, int position, long id) {
		super.onListItemClick(l, v, position, id);
		
		
		
       
		
		
		String title = resorts.get(position).get(0).toString();
		String link = resorts.get(position).get(1).toString();
		String description = resorts.get(position).get(2).toString();
		String tempMax = resorts.get(position).get(3).toString();
		String tempMin = resorts.get(position).get(4).toString();
		String wind = resorts.get(position).get(5).toString();
		String snow = resorts.get(position).get(6).toString();
		String weather = resorts.get(position).get(7).toString();
		String date = resorts.get(position).get(7).toString();
		
		((MyApplication) this.getApplication()).MyApplication(title, link, description, tempMax, tempMin, wind, snow, weather, date);
		((MyApplication) this.getApplication()).setResortSelected(true);
		Log.i("ResortList", "adding info to myapplication");
		
		
		Intent ShowResortGenInfoIntent = new Intent(this, ShowResortGeneralInfo.class);		
		startActivity(ShowResortGenInfoIntent);
		
		
	}
	
	
	
	
	public void testResponse(CharSequence text) { 
    	Context context = getApplicationContext();
    	int duration = Toast.LENGTH_SHORT;

    	Toast toast = Toast.makeText(context, text, duration);
    	toast.show();
    }
    
}